package example.net;

import java.net.InetAddress;
import java.net.Socket;

/**
 * Created by lenovo on 2016/11/7 0007.
 * net.Socket 类的 getInetAddress() 方法来连接到指定主机
 */
public class ConnectHost {
    public static void main(String[] args) {
        try {
            InetAddress addr;
            Socket sock = new Socket("www.w3cschool.cc", 80);
            addr = sock.getInetAddress();
            System.out.println("连接到 " + addr);
            sock.close();
        } catch (java.io.IOException e) {
            System.out.println("无法连接 " + args[0]);
            e.printStackTrace();
        }
    }
}
